package com.sky.controller.admin.category;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类管理接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping
    @ApiOperation(value = "新增分类")
    public Result<String> category(@RequestBody CategoryDTO categoryDTO) {
        categoryService.savecategory(categoryDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation(value = "分页查询分类")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {

        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
    @PostMapping("/status/{status}")
    @ApiOperation(value = "修改分类状态")
    public Result<String> status(@PathVariable int status,Long id) {
        categoryService.status(status,id);
        return Result.success();
    }
    @PutMapping
    @ApiOperation(value = "修改分类")
    public Result<String> update(@RequestBody CategoryDTO categoryDTO) {
        categoryService.update(categoryDTO);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation(value = "删除分类")
    public Result<String> delete(Long id) {
        categoryService.delete(id);
        return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation(value = "查询分类")
    public Result<List<CategoryDTO>> list() {

        List<CategoryDTO> list = categoryService.list();
        return Result.success(list);
    }
}
